<?php

namespace app\api\controller\wdsxh\single;
use app\common\controller\Api;

/**
 * 分类
 */
class Category extends Api
{
    protected $noNeedLogin = ['*'];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];
    public function index(){
        $query = (new \app\admin\model\wdsxh\single\Category())
            ->where('status', '1')
            ->where('pid', 0)
            ->where('deletetime', 'NULL')
            ->order('weigh desc,id desc')
            ->field('id,name,image')
            ->select();
        $this->success('请求成功',$query);
    }

    public function secondary_category(){
        $param = $this->request->param();
        $where = [];
        $where['status'] = array('eq','1');
        $page = isset($param['page']) ? $param['page'] : '';
        $limit = isset($param['limit']) ? $param['limit'] : 10;
        $count =(new \app\admin\model\wdsxh\single\Category())
            ->where('pid', $param['category_id'])
            ->where('pid > 0')
            ->where('deletetime', 'NULL')
            ->where($where)
            ->count();
        $data = (new \app\admin\model\wdsxh\single\Category())
            ->where('pid', $param['category_id'])
            ->where('pid > 0')
            ->where('deletetime', 'NULL')
            ->where($where)
            ->page($page,$limit)
            ->order('weigh desc,id desc')
            ->field('id,name,image')
            ->select();
        $this->success('请求成功',['count'=>$count,'data'=>$data]);
    }


}